package io.aircraft.modules.wms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.aircraft.common.page.PageData;
import io.aircraft.common.service.impl.CrudServiceImpl;
import io.aircraft.common.utils.ConvertUtils;
import io.aircraft.common.utils.ProcResult;
import io.aircraft.modules.sys.dto.SysUserDTO;
import io.aircraft.modules.sys.service.SysUserService;
import io.aircraft.modules.wms.dao.TrkPostDao;
import io.aircraft.modules.wms.dto.TrkPostDTO;
import io.aircraft.modules.wms.entity.TrkPostEntity;
import io.aircraft.modules.wms.service.TrkPostService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 设备任务
 *
 * @author Cycle gengruyi01@163.com
 * @since 1.0.0 2022-10-21
 */
@Service
public class TrkPostServiceImpl extends CrudServiceImpl<TrkPostDao, TrkPostEntity, TrkPostDTO> implements TrkPostService {
    @Override
    public PageData<TrkPostDTO> page(Map<String, Object> params) {
        IPage<TrkPostEntity> page = baseDao.selectPage(
                getPage(params, "post_id", true),
                getWrapper(params)
        );
        return getPageData(page, TrkPostDTO.class);
    }

    @Override
    public QueryWrapper<TrkPostEntity> getWrapper(Map<String, Object> params) {
        String contNo = (String) params.get("contNo");

        QueryWrapper<TrkPostEntity> wrapper = new QueryWrapper<>();
        wrapper.eq(StringUtils.isNotBlank(contNo), "cont_no", contNo);

        return wrapper;
    }

    @Override
    public TrkPostDTO selectOneByPk(String requestPk) {
        QueryWrapper<TrkPostEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("request_pk", requestPk);
        TrkPostEntity entity = baseDao.selectOne(wrapper);
        return ConvertUtils.sourceToTarget(entity, TrkPostDTO.class);
    }

    @Override
    public ProcResult callbackProc(Long id) {
        ProcResult procResult = new ProcResult();
        return procResult;
    }

    @Override
    public int batchSave(List<TrkPostEntity> trkList) {
        return baseDao.batchInsert(trkList);
    }
}